package com.zhigh.calcite.startproject.configuration;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
public class CalciteConfiguration {
    static {
        try {
            Class.forName("org.apache.calcite.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    @Bean
    public DataSource dataSource() {
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl("jdbc:calcite:model=src/main/resources/shemas/model.json");
        config.addDataSourceProperty("lex", "JAVA");
        config.addDataSourceProperty("caseSensitive", false);
        config.setUsername("admin");
        config.setPassword("admin");
        return new HikariDataSource(config);
    }

}
